package com.jxt.myjxtmanager.ui.fragment;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ListView;


import com.jxt.myjxtmanager.BaseFragment;
import com.jxt.myjxtmanager.R;
import com.jxt.myjxtmanager.adapter.BaseAdapterHelper;
import com.jxt.myjxtmanager.adapter.QuickAdapter;
import com.jxt.myjxtmanager.entity.AskForLeaveBean;
import com.jxt.myjxtmanager.ui.inter.AskLeaveInter;
import com.jxt.myjxtmanager.ui.presenter.AskLeavePresenter;
import com.jxt.myjxtmanager.utils.ToastUtil;

import java.util.List;

/**
 * Created by qm on 2017/3/10 0010.
 */
public class LeaveForAskFragment extends BaseFragment implements AskLeaveInter {
    private ListView list_frag_homework;
    private List<AskForLeaveBean> askForLeaveBeans;
    private AskLeavePresenter presenter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_leave_for_ask;
    }

    @Override
    protected void initView() {

        list_frag_homework = (ListView) mView.findViewById(R.id.list_frag_homework);
        presenter = new AskLeavePresenter(getActivity(), this);
        presenter.RequestData();
    }

    @Override
    public void setMyAdapter() {
        presenter.dismissDialog();
        askForLeaveBeans = presenter.getDataList();
        if (askForLeaveBeans == null) {
            return;
        }
        LeaveForAskAdapter leaveForAskAdapter = new LeaveForAskAdapter(getActivity(), R.layout.item_ask_leave, askForLeaveBeans);
        list_frag_homework.setAdapter(leaveForAskAdapter);
    }

    @Override
    public void updateRecycler() {

    }

    @Override
    public void showToastMsg(String msg) {
        if (!TextUtils.isEmpty(msg)) {
            ToastUtil.showToast(getActivity(), msg);
        }
    }

    class LeaveForAskAdapter extends QuickAdapter<AskForLeaveBean> {

        public LeaveForAskAdapter(Context context, int layoutId,
                                  List<AskForLeaveBean> datas) {
            super(context, layoutId, datas);
            // TODO Auto-generated constructor stub
        }

        @Override
        protected void convert(BaseAdapterHelper helper, AskForLeaveBean item) {
            // TODO Auto-generated method stub
            helper.setText(R.id.tv_leave_update_content, item.getLeaveReason());
            helper.setText(R.id.tv_leace_updte_date, "开始时间： " + item.getLeaveTime() + "\n请假时长： " + item.getLeaveHowLong() + "天");
            helper.setText(R.id.tv_leave_type, "状态： " + item.getType());

            if (TextUtils.equals(item.getType(), "通过")) {
                helper.setBackgroundColor(R.id.rel_ask_leave_item, getResources().getColor(R.color.white));
            } else {
                helper.setBackgroundColor(R.id.rel_ask_leave_item, getResources().getColor(R.color.color_red_tr));
            }


        /*helper.setText(R.id.tv_chat_title, item.getTitle());
        helper.setText(R.id.tv_chat_content, item.getContent());*/
        }

    }
}
